package it.irondev.appturismo.service.impl;

import it.irondev.appturismo.dao.EventsMapper;
import it.irondev.appturismo.dao.EventstypeMapper;
import it.irondev.appturismo.dao.example.EventsExample;
import it.irondev.appturismo.dao.example.EventsExample.Criteria;
import it.irondev.appturismo.entity.Event;
import it.irondev.appturismo.entity.Eventstype;
import it.irondev.appturismo.filter.BaseFilter;
import it.irondev.appturismo.service.IEventService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class EventServiceImpl implements IEventService {

	@Autowired
	EventsMapper eventDao;
	@Autowired
	EventstypeMapper eventTypeDao;
	
	
	
	public Event getEventById(Integer idEvent) {
		return eventDao.selectByPrimaryKey(idEvent);
	}
	
	public List<Event> getEventsByFilter(BaseFilter filter) {
		EventsExample example = null;
		if(filter!=null) {
			example = new EventsExample();
			Criteria criteria = example.createCriteria();
			if(filter.getId()!=null)
				criteria.andIdeventsEqualTo(filter.getId());
			if(filter.getIdlanguage()!=null)
				criteria.andLanguageEqualTo(filter.getIdlanguage());
			example.or(criteria);
			example.setOrderByClause("start_date");
		}
		return eventDao.selectByExample(example);
	}

	public List<Event> getAllEvents() {
		return eventDao.selectByExample(null);
	}

	public void addEvent(Event event) {
		eventDao.insert(event);
	}

	public void updateEvent(Event event) {
		eventDao.updateByPrimaryKeySelective(event);
	}

	public void deleteEvent(Integer idEvent) {
		eventDao.deleteByPrimaryKey(idEvent);
	}

	public List<Eventstype> getAllEventsType() {
		return eventTypeDao.selectByExample(null);
	}



}
